<template>
	<view class="content">
		<u-row customStyle="padding:0 30rpx;" @click="toEdit">
			<u-col span="3">
				<u-avatar v-if="userInfo.avatar" :src="userInfo.avatar   " default-url="src7" size="70" shape="square">
				</u-avatar>
				<u-avatar v-else src='/static/uview/common/logo.png' default-url="src7" size="70" shape="square">
				</u-avatar>
			</u-col>
			<u-col span="9">
				<u-row>
					<u-col span="8">
						<u-row v-if="isLogin"> 
						</u-row>
						<u-row v-if="isLogin">
							<u-col span="4">
								<u--text text='昵称:' size='12' color='#878787'></u--text>
							</u-col>
							<u-col span="6">
								<u--text :text='userInfo.real_name' size='16' color='#878787'></u--text>
							</u-col>
						</u-row>
						<u-row v-if="isLogin">
							<u-col span="4">
								<u--text text='注册时间:' size='12' color='#878787'></u--text>
							</u-col>
							<u-col span="6">
								<u--text mode="date" :text='userInfo.add_time '
									size='12' color='#878787'></u--text>
							</u-col>
						</u-row>
						<u-row class="u-m-t-15" v-if="isLogin">
							<u-col span="4">
								<u--text text='到期时间:' size='12' color='#878787'></u--text>
							</u-col>
							<u-col span="6">
								<u--text mode="date"
									:text='Number(userInfo.vip_end_time )' size='12'
									color='#878787'></u--text>
							</u-col>
						</u-row>
						<u-row class="u-m-t-15" v-else>
							<u-col span="6">
								<u-button type="primary" :plain="true" text="登录" size='small'></u-button>
								<!-- <u--text text='登录' size='18' color='#878787'></u--text> -->
							</u-col>
						</u-row>
					</u-col>
					<u-col span="4">
						<u-tag v-if="myOrder" :text="listT[myOrder.order_type].name" size="medium"
							 plain>
						</u-tag>
						<u-tag v-else text="非会员" size="medium" icon="/static/icon/overTime.png"
							plain>
						</u-tag>
					</u-col>
				</u-row>
			</u-col>
		</u-row>

		<u-cell-group :border='false'>

			<u-cell class="u-m-t-80" @click="navTo(0)" title="门店列表" isLink icon="/static/icon/shop.png">
			</u-cell>
			<u-cell @click="navTo(1)" title="店员管理" isLink icon="/static/icon/person.png"></u-cell>
			<u-cell @click="navTo(2)" title="临期配置" isLink icon="/static/icon/time.png"></u-cell>
			<u-cell @click="navTo(3)" title="货架配置" isLink icon="/static/icon/shelves.png"></u-cell>
			<u-cell @click="navTo(4)" title="升级会员" isLink icon="/static/icon/vip.png"></u-cell>
			<u-cell @click="navTo(5)" title="绑定手机" isLink :value='userInfo.mobile || "未绑定"' icon="/static/icon/phone.png">
			</u-cell>
			<u-cell @click="navTo(6)" title="分享有礼" isLink icon="/static/icon/share.png"></u-cell>
			<u-cell @click="navTo(7)" title="我分享的好友" isLink icon="/static/icon/frinds.png"></u-cell>
			<u-cell @click="navTo(8)" title="意见反馈" isLink icon="/static/icon/opinion.png"></u-cell>


			<u-cell @click="navTo(9)" title="联系客服" isLink icon="/static/icon/service.png"></u-cell>
			<u-cell @click="exitLogin" v-if="isLogin" title="退出登录" isLink icon="/static/icon/switch.png"></u-cell>

		</u-cell-group>
		<u-popup :show="popupShow" @close="close" mode='bottom'>
			<view style="padding: 32rpx;">
				<u-button class="u-m-t-20" shape='circle' type="primary" text="个人版"></u-button>
				<u-button class="u-m-t-20" shape='circle' type="error" text="企业版"></u-button>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	var that
	// import cIsLogin from '@/static/js/cIsLogin.js'
	var UserInfo = require('../../../service/UserInfo.js'),
		mUserInfo;
	var ERShoopManage = require('../../../service/ERShoopManage.js'),
		mERShoopManage;
	import initMixin  from '../../../static/js/initMixin.js' ;
// Vue.mixin(initMixin);
	import mInit from "../../../tools/Init"
	export default {
		mixins: [
				  initMixin
				],
		data() {
			return {
				listT: [{
						name: '一人一店'
					},
					{
						name: '一人多店'
					}
				],
				isLogin: false,
				autoStatus: false,
				userInfo: {},
				popupShow: false,
				value5: 2,
				show: false,
				src: 'https://cdn.uviewui.com/uview/album/1.jpg',
				toast: {
					type: 'loading',
					title: '初始化中',
					message: "初始化中",
					duration: 6000,
					iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/loading.png'
				}
			}
		},
		async onLoad() {
			that = this
			 
			mUserInfo = await new UserInfo(this.mNetTool)
			// mERShoopManage = await new ERShoopManage(this.mNetTool)
			let userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				that.userInfo = userInfo
			}
		},
		mounted() {

		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo')
			that.isLogin = uni.getStorageSync('isLogin')
			let myOrderList =uni.getStorageSync('myOrderList');
			if(myOrderList && myOrderList.rows.length>0){
				this.myOrder = myOrderList.rows[0]
			}
			if (userInfo) {
				that.userInfo = userInfo
				if(userInfo.level == -1){
					uni.navigateTo({
						url:'../login/newUser'
					})
				}
			}
		},
		methods: {
			toEdit() {
				let that = this
				console.log(this.isLogin)
				if (!this.isLogin) {
					uni.showModal({
						content: "您未登录，请先登录！",
						success(r) {
							if (r.confirm) {
								if (that.autoStatus) { //支持一键登录
									console.log('进入一键登录')
									that.keyLogin()
								} else {
									// #ifdef MP-WEIXIN
									uni.navigateTo({
										url: '../login/keyLogin'
									})
									// #endif
									// #ifdef APP-PLUS || H5
									uni.navigateTo({
										url: '../login/login'
									})
									// #endif

								}

							}
						}
					})
					return
				}
				uni.navigateTo({
					url: 'userInfoEdit/userInfoEdit'
				})
			},
			exitLogin() {
				uni.showModal({
					content: '要退出登录吗？',
					success(e) {
						if (e.confirm) {
							 
							uni.clearStorageSync()
							uni.setStorageSync('isLogin', false)
							uni.setStorageSync('token', token)
							uni.reLaunch({
								url: '../home/home'
							})
						}
					}
				})
			},
			close() {
				this.popupShow = false
				// console.log('close');
			},
			navTo(i) {
				if (!this.isLogin && i < 8) {
					uni.showModal({
						content: "您未登录，请先登录！",
						success(r) {
							if (r.confirm) {
								if (that.autoStatus) { //支持一键登录
									console.log('进入一键登录')
									that.keyLogin()

								} else {
									// #ifdef MP-WEIXIN
									uni.navigateTo({
										url: '../login/keyLogin'
									})
									// #endif
									// #ifdef APP-PLUS
									uni.navigateTo({
										url: '../login/login'
									})
									// #endif
								}

							}
						}
					})
					return
				}
				
				if (i === 10) {
					this.popupShow = true
					return
				}
				let a = [
					'../shopList/shopList',
					'../staffList/staffList',
					'../expirationDateSetting/expirationDateSetting',
					'../goodsShelf/goodsShelf',
					'../VIP/VIP',
					'../bindPhone/bindPhone',
					'../shareGift/shareGift',
					'../myFriends/myFriends',
					'../feedBack/feedBack',
					'../serviceContact/serviceContact',
				]
				if(i==0 || i ==1 || i == 2 || i == 3){
					mUserInfo.isVip(res => {
						console.log(res)
						if(!res.success){
							uni.$u.toast('您的会员已过期，请充值')
							 return
						}else{
							uni.navigateTo({
								url: a[i]
							})
						}
					})
				}else{
					uni.navigateTo({
						url: a[i]
					})
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 0 0rpx;
	}
</style>
